<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/jsp/head.jsp"%>
<%@ include file="/jsp/jslib.jsp"%>
<script type="text/javascript">
PAGE_CONFIG = {
	'MENU_INDEX' : 2,'LI_INDEX' : 3
};
</script>
</head>
<body>
<%@ include file="/jsp/banner.jsp"%>
<div class="am-cf admin-main">
	<%@ include file="/jsp/menu.jsp"%>
	
	<!-- content start -->
	<div class="admin-content">
		<div class="admin-content-body">
		
		<!-- ***** 分离出去 动态加载 start ***** -->
		<div class="am-g">
			<div class="am-u-sm-12 am-u-md-6 am-padd-top-20">
				<div class="am-btn-toolbar">
					<div class="am-btn-group am-btn-group-xs">
						<button id="update" type="button" class="am-btn am-btn-default"><span class="am-icon-save"></span> 修改</button>
					</div>
					<div class="am-btn-group am-btn-group-xs">
						<button id="delete" type="button" class="am-btn am-btn-default"><span class="am-icon-trash-o"></span> 删除</button>
					</div>
				</div>
			</div>
		</div>
		
		<hr/>
		
		<div class="am-g">
		    <div class="am-u-sm-12">
		        <form class="am-form">
		            <table class="am-table am-table-striped am-table-hover table-main am-u-sm-6">
		                <thead>
		                    <tr>
		                        <th class="table-check"></th>
		                        <th class="table-title">员工编号</th>
		                        <th class="table-title">员工姓名</th>
		                        <th class="table-title">职位</th>
		                        <th class="table-title">联系电话</th>
		                        <th class="table-title">所属部门</th>
		                        <th class="table-title">权限</th>
		                    </tr>
		                </thead>
		
		                <tbody>
		                	<c:forEach items="${fgStaffList}" var="staff">
		                		<tr>
			                    	<td><input type="radio" name="staff" value='${staff.staffId}' /></td>
			                    	<td id="staff_id_${staff.staffId}">${staff.staffId}</td>
			                        <td id="staff_name_${staff.staffId}">${staff.staffName}</td>
			                        <td>${staff.positionName}</td>
			                        <td>${staff.staffMobile}</td>
			                        <td>${staff.companyName}</td>
			                        <td>
			                        	<c:if test="${staff.permission == '0'}">员工</c:if>
			                        	<c:if test="${staff.permission == '1'}">主管</c:if>
			                        	<c:if test="${staff.permission == '2'}">管理员</c:if>
			                        </td>
			                        
			                        <td id="staff_positionId_${staff.staffId}" hidden>${staff.positionId}</td>
			                        <td id="staff_companyId_${staff.staffId}" hidden>${staff.companyId}</td>
			                        <td id="staff_permission_${staff.staffId}" hidden>${staff.permission}</td>
		                        </tr>
		                	</c:forEach>
	                    </tbody>
		            </table>
		
		        </form>
		    </div>
		</div>
		
		<!-- ***** 分离出去 动态加载 end ***** -->
		
		</div>
	</div>
	<!-- content end -->
</div>

<script type="text/javascript">
$("#delete").click(function(){
	var permission = '${sessionScope.permission}';
	if(permission != 2) {
		alert("无权限删除");
		return;
	}
	
	var val=$('input:radio[name="staff"]:checked').val();
	if(val == null) {
		alert("请选择一行记录进行操作");
		return;
	}
	location.href= "${ctx}/staff/delete?staffId=" + val;
});

$("#update").click(function(){
	var val=$('input:radio[name="staff"]:checked').val();
	if(val == null) {
		alert("请选择一行记录进行操作");
		return;
	}
	
	var staffId = $("#staff_id_"+val).text();
	var staffName = $("#staff_name_"+val).text();
	var companyId = $("#staff_companyId_"+val).text();
	var positionId = $("#staff_positionId_"+val).text();
	var permission = $("#staff_permission_"+val).text();
    
	if('${sessionScope.permission}' == 0) {
		if(staffId != '${sessionScope.staffId}') {
			alert("无编辑权限");
			return;
		}
	}
	
	window.location.href="${ctx}/biz_staff_add.jsp?staffId="+staffId+"&staffName="+staffName+"&companyId="+companyId+"&positionId="+positionId+"&permission="+permission;
});
</script>
<!-- +"&fgCompanyList="+${fgCompanyList}+"&fgPositionList="+${fgPositionList} -->
</body>
</html>